﻿//======================================================================
//
//        Copyright (C) 2015   
//        All rights reserved
//
//        filename : Y_SaleMonthDetl
//        description : 运营部网点明细报表
//        created by XXX at  20160504
//
//======================================================================
using System;
using System.Data;
using CardLogistics.Web.Components;
using CardLogistics.DAL;
using System.Text;

namespace CardLogistics.Web.MainPage.Report.DepReport
{
    public partial class Y_SaleMonthDetl : BasePage
    {
        private static readonly DepReportData DepDAL = new DepReportData();

        #region 查询
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            if (txt_Data.Text.Trim().Length > 0)
            {
                string startV = txt_Data.Text + "-01";//统计月份的第一天
                string endV = DateTime.Parse(startV).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");//统计月份的最后一天
                BindData(startV, endV);
            }
            else
                ShowMessageBox("请选择统计月份！");
                txt_Data.Focus();
        }
        #endregion

        #region 绑定数据
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="startData"></param>
        /// <param name="endData"></param>
        private void BindData(string startData, string endData)
        {
            DataTable dt = DepDAL.GetYSaleMonthDetl(startData, endData);
            StringBuilder sbStr = new StringBuilder();
            StringBuilder sbTitle = new StringBuilder("<tr><td>网点名称</td><td>卡类型</td><td>上月结存</td><td>本月发卡</td><td>本月售卡</td><td>本月退回</td><td>本月异常</td><td>本月结存</td></tr>");//数量
            sbStr.Append("<table  border='1' style='font-size:16px;white-space: nowrap; '>");
            sbStr.Append(sbTitle);//标题头
            //内容
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sbStr.Append(" <tr>");
                sbStr.Append("<td style='width:70px'>" + dt.Rows[i]["SalesName"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["cardtypename"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["上月结存"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["本月发卡"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["本月售卡"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["本月退回"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["本月异常"].ToString() + "</td>");
                sbStr.Append("<td>" + dt.Rows[i]["本月结存"].ToString() + "</td>");
                sbStr.Append(" </tr>");
            }
            d_info.InnerHtml = sbStr.ToString() + "</table>";
        }
        #endregion

        #region 导出事件
        /// <summary>
        /// 导出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            if (d_info.InnerHtml.Length > 50)
            {
                ExportExcel(txt_Data.Text, d_info);
            }
            else
                ShowMessageBox("请先查询出报表内容！");
        }
        #endregion
    }
}